package view.component.weapon.flute
{
	import enums.main.UISize;
	
	import feathers.controls.Button;
	import feathers.controls.Label;
	import feathers.controls.ScrollContainer;
	import feathers.controls.TabBar;
	import feathers.data.ListCollection;
	
	import util.FG2FUGenerator;
	import util.WeaponUtil;
	
	import view.event.weapon.WeaponSearchViewEvent;
	import view.component.weapon.BaseShortWeaponSearchView;
	
	/**
	 * 笛子-搜索界面
	 * @author £iang
	 * 
	 */	
	public class FluteSearchView extends BaseShortWeaponSearchView
	{
		//-----------------------------
		// variables
		//-----------------------------
		
		/** 音色标题 */
		public var melodyTitle:Label;
		/** 音色选项 */
		public var melodyTabBar:TabBar;
		/** 音色选项滚动条容器 */
		public var melodyTabSC:ScrollContainer;
		
		//-----------------------------
		// properties
		//-----------------------------
		
		//-----------------------------
		// setter&getter
		//-----------------------------
		
		//-----------------------------
		// methods
		//-----------------------------
		
		override protected function initialize():void
		{
			super.initialize();
			
			var labelVec:Vector.<String>;
			var dataProvider1:ListCollection = new ListCollection( [] );
			var len:int;
			var i:int;
			var obj:Object;
			
			melodyTitle = new Label();
			melodyTitle.text = "音色：";
			mainSC.addChild( melodyTitle );
			
			labelVec = WeaponUtil.getMelodyTypeTextVec();
			labelVec.splice( 0, 0, "全部" );
			melodyTabBar = new TabBar();
			melodyTabBar.gap = 15 * this.dpiScale;
			len = labelVec.length;
			
			for ( i = 0; i < len; i ++ )
			{
				obj = new Object();
				obj.label = labelVec[ i ];
				dataProvider1.push( obj );
			}
			
			melodyTabBar.dataProvider = dataProvider1;
			melodyTabBar.tabFactory = mainTabFactory;
			melodyTabSC = new ScrollContainer();
			mainSC.addChild( melodyTabSC );
			melodyTabSC.addChild( melodyTabBar );
		}
		
		override protected function draw():void
		{
			super.draw();
			melodyTitle.x = 20 * this.dpiScale;
			melodyTitle.y = 360 * this.dpiScale;
			melodyTabSC.x =  110 * this.dpiScale;
			melodyTabSC.y =  360 * this.dpiScale;
			melodyTabSC.width = UISize.MAIN_W - 130 * this.dpiScale;
		}
		
		override public function dispatchSearchEvent():void
		{
			var weaponSearchEvent:WeaponSearchViewEvent = 
				new WeaponSearchViewEvent( WeaponSearchViewEvent.SEARCH );
			
			weaponSearchEvent.rank = levelTabBar.selectedIndex + 1;
			weaponSearchEvent.awakeType = awakenTabBar.selectedIndex;
			weaponSearchEvent.attribute = attributeTabBar.selectedIndex - 1;
			weaponSearchEvent.add = addSharpTabBar.selectedIndex;
			weaponSearchEvent.blade = sharpTabBar.selectedIndex;
			weaponSearchEvent.slot = slotTabBar.selectedIndex - 1;
			weaponSearchEvent.sort = sortTabBar.selectedIndex;
			weaponSearchEvent.melodyType = melodyTabBar.selectedIndex - 1;
			dispatchCommonEvent( weaponSearchEvent );
		}
		
		//-----------------------------
		// events
		//-----------------------------
		
		//-----------------------------
		// dispose
		//-----------------------------
		
		/**
		 * 析构函数 
		 * 
		 */		
		override public function dispose():void
		{
			var i:int;
			var button:Button;
			
			melodyTitle.dispose(); melodyTitle = null;
			
			for ( i = 0; i < melodyTabBar.numChildren; i ++ )
			{
				if ( melodyTabBar.getChildAt( i ) is Button )
				{
					button = melodyTabBar.getChildAt( i ) as Button;
					button.dispose();
					FG2FUGenerator.deepDisposeButtonComp( button );
					button = null;
				}
			}
			
			melodyTabSC.dispose(); melodyTabSC = null;
			super.dispose();
		}
		
		//-----------------------------
		// construction
		//-----------------------------
		
		/**
		 * 构造函数
		 *
		 */
		public function FluteSearchView()
		{
			super();
			insertOffset = 60;
			searchAreaH = 540;
			weaponType = "flute";
		}
	}
}